<% layout('/layouts/default.html', {title: '课程表管理', libs: ['dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header">
			<div class="box-title">
				<i class="fa icon-notebook"></i> ${text('课程表管理')}
			</div>
			<div class="box-tools pull-right">
			    
				<a href="#" class="btn btn-default" id="btnSearch" title="${text('查询')}"><i class="fa fa-filter"></i> ${text('查询')}</a>
				<a href="#" class="btn btn-default" id="btnRefreshTree" title="${text('刷新')}"><i class="fa fa-refresh"></i> ${text('刷新')}</a>
				<a href="#" class="btn btn-default" id="btnExpandTreeNode" title="${text('展开一级')}"><i class="fa fa-angle-double-down"></i> ${text('展开')}</a>
				<a href="#" class="btn btn-default" id="btnCollapseTreeNode" title="${text('折叠全部')}"><i class="fa fa-angle-double-up"></i> ${text('折叠')}</a>
				<% if(hasPermi('zx:course:tcourses:edit')){ %>
					<a href="${ctx}/zx/course/tcourses/form?courseExplain=0" class="btn btn-default btnTool" title="${text('新增课程表')}"><i class="fa fa-plus"></i> ${text('新增')}</a>
				<% } %>
				<!--<div class="btn-group">
					<a href="javascript:" class="btn btn-default dropdown-toggle" data-toggle="dropdown">
						<i class="fa fa-navicon"></i> <span class="caret"></span>
					</a>
					<ul class="dropdown-menu">
						<li><a href="javascript:" id="btnExport"><i class="glyphicon glyphicon-export"></i> ${text('导出')}</a></li>
						<li><a href="javascript:" id="btnImport"><i class="glyphicon glyphicon-import"></i> ${text('导入')}</a></li>
					</ul>
				</div>-->
			</div>
		</div>
		<div class="box-body">
			<#form:form id="searchForm" model="${tcourses}" action="${ctx}/zx/course/tcourses/listData" method="post" class="form-inline hide"
					data-page-no="${parameter.pageNo}" data-page-size="${parameter.pageSize}" data-order-by="${parameter.orderBy}">
				<div class="form-group">
					<label class="control-label">${text('课程标题')}：</label>
					<div class="control-inline">
						<#form:input path="courseTitle" maxlength="64" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group hide">
					<label class="control-label">${text('课程简介')}：</label>
					<div class="control-inline">
						<#form:input path="courseSimple" maxlength="255" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group hide">
					<label class="control-label">${text('课程封面图')}：</label>
					<div class="control-inline">
						<#form:input path="courseCover" maxlength="300" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group hide">
					<label class="control-label">${text('课程内容')}：</label>
					<div class="control-inline">
						<#form:input path="courseContent" maxlength="500" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group hide">
					<label class="control-label">${text('课程标签')}：</label>
					<div class="control-inline">
						<#form:input path="courseLabel" maxlength="255" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('课程分类')}：</label>
					<div class="control-inline width-120">
					<#form:select path="courseItem" dictType="t_course_item_query" blankOption="true" class="form-control width-120 isQuick"/>
					</div>
				</div>
				<div class="form-group hide">
					<label class="control-label">${text('讲师的登录名')}：</label>
					<div class="control-inline">
						<#form:input path="userLoginCode" maxlength="50" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group hide">
					<label class="control-label">${text('课程价格')}：</label>
					<div class="control-inline">
						<#form:input path="coursePrice" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group hide">
					<label class="control-label">${text('讲师主键')}：</label>
					<div class="control-inline">
						<#form:input path="teacherId" maxlength="50" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group hide">
					<label class="control-label">${text('点赞量')}：</label>
					<div class="control-inline">
						<#form:input path="likeNum" maxlength="10" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group hide">
					<label class="control-label">${text('课程说明0代表课程；1表示课时')}：</label>
					<div class="control-inline">
						<#form:input path="courseExplain" maxlength="10" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group hide">
					<label class="control-label">${text('观看量')}：</label>
					<div class="control-inline">
						<#form:input path="lookNum" maxlength="10" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group hide">
					<label class="control-label">${text('status')}：</label>
					<div class="control-inline width-120">
						<#form:select path="status" dictType="sys_search_status" blankOption="true" class="form-control isQuick"/>
					</div>
				</div>
				<div class="form-group hide">
					<label class="control-label">${text('备注做附件的保存路径')}：</label>
					<div class="control-inline">
						<#form:input path="remarks" maxlength="1555" class="form-control width-120"/>
					</div>
				</div>
				<div class="form-group">
					<button type="submit" class="btn btn-primary btn-sm">${text('查询')}</button>
					<button type="reset" class="btn btn-default btn-sm">${text('重置')}</button>
				</div>
			</#form:form>
			<table id="dataGrid"></table>
		</div>
	</div>
</div>
<% var userType = isNotBlank(parameter.userType)?parameter.userType:'employee'; %>
<div class="hide"><#form:listselect id="userSelect" title="${text('用户选择')}"
	url="${ctx}/sys/user/userSelect?userType=${userType}" allowClear="false" 
	checkbox="true" itemCode="userCode" itemName="userName"/></div>
<% } %>
<script>
function btnAddAdmin(id){
	 
	$('#userSelectName').click();
}
// 初始化DataGrid对象
$('#dataGrid').dataGrid({
	searchForm: $("#searchForm"),
	columnModel: [
		{header:'${text("标题")}', name:'courseTitle', index:'a.course_title', width:250, align:"left", frozen:true, formatter: function(val, obj, row, act){
			var courseExplain=row.courseExplain;
			return '<a href="${ctx}/zx/course/tcourses/form?courseExplain='+courseExplain+'&id='+row.id+'" class="btnList" data-title="${text("编辑课程表")}">'+(val||row.courseTitle)+'</a>';
		}},
		{header:'${text("说明")}', name:'courseExplain', index:'a.course_explain', width:50, align:"center", formatter: function(val, obj, row, act){
			return js.getDictLabel(${@DictUtils.getDictListJson('t_course_query')}, val, '${text("")}', true);
		}},
		{header:'${text("简介")}', hidden:true,name:'courseSimple', index:'a.course_simple', width:150, align:"left"},
		{header:'${text("封面图")}', hidden:true,name:'courseCover', index:'a.course_cover', width:150, align:"left"},
		{header:'${text("内容")}', hidden:true,name:'courseContent', index:'a.course_content', width:150, align:"left"},
		{header:'${text("标签")}',hidden:true, name:'courseLabel', index:'a.course_label', width:150, align:"left", formatter: function(val, obj, row, act){
			return js.getDictLabel(${@DictUtils.getDictListJson('t_course_label_query')}, val, '${text("")}', true);
		}},
		{header:'${text("分类")}',name:'courseItem', index:'a.course_item', width:100, align:"left", formatter: function(val, obj, row, act){
			var courseExplain=row.courseExplain;
			if(courseExplain==4){
				return js.getDictLabel(${@DictUtils.getDictListJson('t_exercises_query')}, val, '${text("")}', true);
			}
			return js.getDictLabel(${@DictUtils.getDictListJson('t_course_item_query')}, val, '${text("")}', true);
		}},
		{header:'${text("讲师")}',hidden:true, name:'userLoginCode', index:'a.user_login_code', width:150, align:"left"},
		{header:'${text("价格")}', hidden:true,name:'coursePrice', index:'a.course_price', width:150, align:"right", formatter: function(val, obj, row, act){
			return js.formatNumber(val, 2, false, ''); // 数值类型格式化 (原始数值, 小数位数, 是否千分位, 默认值，金额情况下设置0.00);
		}},
		{header:'${text("讲师主键")}',hidden:true, name:'teacherId', index:'a.teacher_id', width:150, align:"left"},
		{header:'${text("点赞量")}',hidden:true, name:'likeNum', index:'a.like_num', width:150, align:"center"},
		{header:'${text("观看量")}',hidden:true, name:'lookNum', index:'a.look_num', width:150, align:"center"},
		{header:'${text("当前层级排序号")}',hidden:true, name:'treeSort', index:'a.tree_sort', width:150, align:"center"},
		{header:'${text("update_date")}',hidden:true, name:'updateDate', index:'a.update_date', width:150, align:"center"},
		{header:'${text("状态")}', name:'status',hidden:true, index:'a.status', width:150, align:"center", formatter: function(val, obj, row, act){
			return js.getDictLabel(${@DictUtils.getDictListJson('sys_search_status')}, val, '${text("未知")}', true);
		}},
		{header:'${text("备注做附件的保存路径")}',hidden:true, name:'remarks', index:'a.remarks', width:150, align:"left"},
		{header:'${text("操作")}', name:'actions', width:220, sortable:false, title:false, formatter: function(val, obj, row, act){
			var actions = [];
			var courseExplain=row.courseExplain;
			<% if(hasPermi('zx:course:tcourses:edit')){ %>
				actions.push('<a href="${ctx}/zx/course/tcourses/form?courseExplain='+courseExplain+'&id='+row.id+'" class="btnList" title="${text("编辑课程表")}"><i class="fa fa-pencil"></i></a>&nbsp;');
				if (row.status == Global.STATUS_NORMAL){
					actions.push('<a href="${ctx}/zx/course/tcourses/disable?id='+row.id+'" class="btnList" title="${text("停用课程表")}" data-confirm="${text("确认要停用该课程表吗？")}"><i class="glyphicon glyphicon-ban-circle"></i></a>&nbsp;');
				} else if (row.status == Global.STATUS_DISABLE){
					actions.push('<a href="${ctx}/zx/course/tcourses/enable?id='+row.id+'" class="btnList" title="${text("启用课程表")}" data-confirm="${text("确认要启用该课程表吗？")}"><i class="glyphicon glyphicon-ok-circle"></i></a>&nbsp;');
				}
				actions.push('<a href="${ctx}/zx/course/tcourses/delete?id='+row.id+'" class="btnList" title="${text("删除课程表")}" data-confirm="${text("确认要删除该课程表及所有子课程表吗？")}" data-deltreenode="'+row.id+'"><i class="fa fa-trash-o"></i></a>&nbsp;');
				if(courseExplain==0){
					actions.push('<a href="${ctx}/zx/course/tcourses/listUser?courseExplain='+courseExplain+'&id='+row.id+'" class="btn btn-default btn-xs btnList" title="${text("授权用户")}"><i class="fa fa-check-circle-o"></i>${text("授权用户")}</a>&nbsp;');
					actions.push('<a href="${ctx}/zx/course/tcourses/form?courseExplain=1&parentCode='+row.id+'" class="btnList" title="${text("新增课时")}"><i class="fa fa-plus-square"></i></a>&nbsp;');
				}else if(courseExplain==1){
					actions.push('<a href="${ctx}/zx/course/tcourses/form?courseExplain=6&parentCode='+row.id+'" class="btnList" title="${text("新增练习题题目")}"><i class="fa fa-plus-square"></i></a>&nbsp;');
				}else if(courseExplain==2){
					//资料也不用添加下级
				}else if(courseExplain==3){
					actions.push('<a href="${ctx}/zx/course/tcourses/form?courseExplain=4&parentCode='+row.id+'" class="btnList" title="${text("新增问题")}"><i class="fa fa-plus-square"></i></a>&nbsp;');
				}else if(courseExplain==4){
					actions.push('<a href="${ctx}/zx/course/tcourses/form?courseExplain=5&parentCode='+row.id+'" class="btnList" title="${text("新增问题")}"><i class="fa fa-plus-square"></i></a>&nbsp;');
				}else if(courseExplain==6){
					actions.push('<a href="${ctx}/zx/course/tcourses/form?courseExplain=4&parentCode='+row.id+'" class="btnList" title="${text("新增练习题题目")}"><i class="fa fa-plus-square"></i></a>&nbsp;');
				}
				
			<% } %>
			return actions.join('');
		}}
	],
	treeGrid: true,			// 启用树结构表格
	defaultExpandLevel: 0,	// 默认展开的层次
	expandNodeClearPostData: 'courseTitle,courseSimple,courseCover,courseContent,courseLabel,courseItem,userLoginCode,coursePrice,teacherId,likeNum,courseExplain,lookNum,remarks,', // 展开节点清理请求参数数据（一般设置查询条件的字段属性，否则在查询后，不能展开子节点数据）
	// 加载成功后执行事件
	ajaxSuccess: function(data){
		
	}
});
$('#btnExport').click(function(){
	js.ajaxSubmitForm($('#searchForm'), {
		url:'${ctx}/zx/course/tcourses/exportData',
		downloadFile:true
	});
});
$('#btnImport').click(function(){
	js.layer.open({
		type: 1,
		area: ['400px'],
		title: '${text("导入课程数据")}',
		resize: false,
		scrollbar: true,
		content: js.template('importTpl'),
		success: function(layero, index){
			layero.find('input[type="checkbox"]').iCheck();
		},
		btn: ['<i class="fa fa-check"></i> ${text("导入")}',
			'<i class="fa fa-remove"></i> ${text("关闭")}'],
		btn1: function(index, layero){
			var form = {
				inputForm: layero.find('#inputForm'),
				file: layero.find('#file').val()
			};
		    if (form.file == '' || (!js.endWith(form.file, '.xls') && !js.endWith(form.file, '.xlsx'))){
		    	js.showMessage("${text('文件不正确，请选择后缀为“xls”或“xlsx”的文件。')}", null, 'warning');
		        return false;
		    }
			js.ajaxSubmitForm(form.inputForm, function(data){
				js.showMessage(data.message);
				if(data.result == Global.TRUE){
					js.layer.closeAll();
				}
				page();
			}, "json");
			return true;
		}
	});
});



</script>
<script id="importTpl" type="text/template">//<!--
<form id="inputForm" action="${ctx}/zx/course/tcourses/importData" method="post" enctype="multipart/form-data"
	class="form-horizontal mt20 mb10" style="overflow:auto;max-height:200px;">
	<div class="row">
		<div class="col-xs-12 col-xs-offset-1">
			<input type="file" id="file" name="file" class="form-file"/>
			<div class="mt10 pt5">
				<#form:checkbox name="updateSupport" label="${text('是否更新已经存在的课程数据')}" class="form-control"
					title="${text('如果课程编码已经存在，更新这条数据。')}"/> &nbsp;
				<a href="${ctx}/zx/course/tcourses/importTemplate" class="btn btn-default btn-xs"><i class="fa fa-file-excel-o"></i> ${text('下载模板')}</a>
			</div>
			<font color="red" class="pull-left mt10">
				${text('提示：仅允许导入“xls”或“xlsx”格式文件！')}
			</font>
		</div>
	</div>
</form>
//--></script>